package com.jone.bang.service;



import java.util.Calendar;

import com.jone.bang.db.ConfigCenter;
import com.jone.bang.util.Constant;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class BootCompletedReceiver extends BroadcastReceiver {
   
   public void onReceive(Context context, Intent intent) {
	   
	   Log.d("BootCompleted", "china hot search begin alarm service!");
	   
	   if(ConfigCenter.getValue(context, Constant.KEY_ENABLE_NOTIFICATION, true)){
		 //启动定时检查
		   Calendar c = Calendar.getInstance();
		   int expectedHour = 18;
		   int nowHour = c.get(Calendar.HOUR_OF_DAY);
		   if(nowHour >=expectedHour){
			   c.add(Calendar.DAY_OF_MONTH, 1);
		   }
		   c.set(Calendar.HOUR_OF_DAY, expectedHour);
		   c.set(Calendar.MINUTE, 20);

		   /* 指定闹钟设置时间到时要运行CallAlarm.class */
	       Intent i = new Intent(context,MyNotification.class);
	       
	       PendingIntent sender = PendingIntent.getBroadcast(context,1, i, 0);
	       /* setRepeating()可让闹钟重复运行 */
	       AlarmManager am;
	       
	       //间隔时间
	       int times= 24*60*60*1000;
	       am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
	       am.setRepeating(AlarmManager.RTC_WAKEUP,
	                 c.getTimeInMillis(),times,sender);
	   }     
   }

}